package cn.com.guage.dynamic.datasource.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author yangdechao
 * @version 1.0
 * @date 2020/07/14 16:36
 */
public class DatasourceContextHolder {
	
    protected final static Logger logger = LoggerFactory.getLogger(DatasourceContextHolder.class);

    public static final String DEFAULT_DATASOURCE = Datasources.DB1;

    private static final ThreadLocal<String> contextHolder = new ThreadLocal<String>();

    public static void setDB(String dbType) {
    	logger.info("切换到{}数据源", dbType);
        contextHolder.set(dbType);
    }

    /**
     * 获取数据源名
     */
    public static String getDB() {
        return contextHolder.get();
    }

    /**
     * 清除数据源名
     */
    public static void clearDB() {
        contextHolder.remove();
    }
}